import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../AppConfig/Config.dart';
import '../../SendGoods/AddGoodsFirst.dart';
import '../../http/NoLoadingGetApi.dart';
import '../../l10n/messages.dart';

class UserAddress extends StatefulWidget {
  const UserAddress({super.key});

  @override
  State<UserAddress> createState() => _UserAddressState();
}

class _UserAddressState extends State<UserAddress> {
  Map userMap={};
  List cityData = [];
  String startCityname ="";
  List startCitycode =[];
  List startAddress=[];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getUserInfo();
  }
  void getUserInfo(){
    NoLoadinggetApiManager.getData(
      context, // 上下文对象，用于显示提示信息等
      'api/auth/shipper/user/getLoginUser', // 您的API端点
      {}, // 查询参数，如果没有可以传递null
          (responseData)  {
        setState(() {
          userMap=responseData['data'];
        });
      },
    );
  }
  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    var messages = AppLocalizations.of(context)!;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        leading: IconButton(icon: Icon(Icons.arrow_back_ios,color: Colors.black,),onPressed: (){Navigator.pop(context);},),
        title: Text(messages["收货地址"],style: TextStyle(fontWeight: FontWeight.w300,fontSize: 16.sp),),
        centerTitle: true,
        backgroundColor: Colors.white,
      ),
      body:userMap.isEmpty?Container(): ListView(
        children: [
          Container(
            color: Colors.white,
            padding: EdgeInsets.only(top: 10.h,bottom: 10.h,left: 15.w,right: 15.w),
            child: Column(
              children: [
                Row(
                  children: [
                    Text("收货人",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                    SizedBox(width: 30.w,),
                    Text(userMap['realName'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                  ],
                ),
                SizedBox(height: 10.h,),
                Container(height: 1.h,color: MyColors.backgreyColor,),
                SizedBox(height: 10.h,),
                Row(
                  children: [
                    Text("手机号码",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                    SizedBox(width: 18.w,),
                    Text(userMap['phoneNum'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                  ],
                ),
                SizedBox(height: 10.h,),
                Container(height: 1.h,color: MyColors.backgreyColor,),
                SizedBox(height: 10.h,),
                GestureDetector(
                  child:   Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("所在地区",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                          SizedBox(width: 18.w,),

                          Text(startCityname!=""?startCityname:"请选择",style: TextStyle(color:startCityname!=""?Colors.black: MyColors.textColor,fontSize: 14.sp),),
                        ],
                      ),
                      Icon(Icons.arrow_forward_ios,color: MyColors.hintColor,size: 14,),
                    ],
                  ),
                  onTap: ()async{
                    final result = await  showModalBottomSheet(context: context,
                        isScrollControlled:true,
                        isDismissible: false, // 设置为 false，点击外部区域不关闭
                        enableDrag: false, // 设置为 false，禁用上滑手势关闭
                        builder: (BuildContext context)
                        {
                          return chooseCitySheet(chooseType: 4 ,cityData: cityData, chooseCityList: [],chooseCodeList: [],);
                        });
                    if (result != null) {
                      setState(() {
                        print(result);
                        startCityname = result[0]+" "+result[1]+" "+result[2];
                        startCitycode =[result[3],result[4],result[5]];
                        startAddress=[result[0],result[1],result[2]];
                      });
                    }
                  },
                ),
                SizedBox(height: 10.h,),
                Container(height: 1.h,color: MyColors.backgreyColor,),
                SizedBox(height: 10.h,),
                Row(

                  children: [
                    Text("详细地址",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                    SizedBox(width: 14.w,),
                    Container(
                      width: screenSize.width-120.w,
                      height: 35.h,
                      decoration: BoxDecoration(
                        color: MyColors.backgreyColor,
                        borderRadius: BorderRadius.all(Radius.circular(10)),
                      ),
                      child:  TextField(
                        decoration: InputDecoration(
                          hintText: '请填写详细地址，不少于5个字',
                          hintStyle:TextStyle(fontSize: 14.sp,color: MyColors.hintColor),
                          filled: true,
                          fillColor: Colors.white,
                          border: InputBorder.none,
                          alignLabelWithHint: true,
                        ),
                        textAlign: TextAlign.left,
                        style: TextStyle(color: Colors.black),
                        onChanged: (value) {
                          setState(() {

                          });
                        },
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
          SizedBox(height: 50.h,),
          Container(margin: EdgeInsets.only(left: 15.w,right: 15.w),
            child:    BrnSmallMainButton(
              title: '保存',
              bgColor: MyColors.themeColor,
              fontSize: 16.sp,
              radius: 30,
              onTap: () {

              },
            ),
          ),
        ],
      ),
    );
  }
}
